package bairui.international.weixin.portal.miniapp.controller.address.address;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_Address;
import bairui.international.service.Service_Address;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 * 获取默认地址
 *
 * @generated
 * 
 * @see STest_C_Address_GetDefault_Get 测试
 *
 */
@Controller
public class C_Address_GetDefault_Get
 extends SC_Address_GetDefault_Get 
{
	
	@Autowired private Service_Address service_Address;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request,
		@RequestParam String skey
	) throws Exception {
		TB_Address bean = service_Address.getDefult(skey);
		if(null == bean){
			bean = service_Address.findFirst(it->it.user.skey.eq(skey));
		}
		if(null == bean){
			return null;
		}
		return new Output(
				bean.getId(),
				bean.getPhone(),
				bean.getName(),
				bean.getArea(),
				bean.getDetailAddress(),
				bean.getTownId(),
				bean.getDefaultFlag()
			);
	}
	
	@AllArgsConstructor
	public static class Output {
		private @Getter Long id;
		private @Getter String phone;
		private @Getter String username;
		private @Getter String area;
		private @Getter String detailAddress;
		private @Getter Long townId;
		private @Getter Boolean defaultFlag;
	}

}
